package com.zhiwei.most.liveEventBus

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import com.jeremyliao.liveeventbus.LiveEventBus

/**
 * Create by alex on 2021/9/6
 * 支持进程、App之间通讯，以下方法不需要考虑反注册的问题，不支持线程通讯
 */

class LiveEventBusHelper private constructor(){

    companion object{
        fun getInstance() = Helper.instance
    }

    private object Helper{
        val instance = LiveEventBusHelper()
    }

    fun <T> post(event: Event<T>){
        LiveEventBus.get<T>(event.key, event.type).post(event.data)
    }

    fun <T> postDelay(event: Event<T>, delay: Long = 1000L){
        LiveEventBus.get<T>(event.key, event.type).postDelay(event.data, delay)
    }

    fun <T> observe(owner: LifecycleOwner, key: String, observer: Observer<T>){
        LiveEventBus.get<T>(key).observe(owner, observer)
    }

    fun <T> observeSticky(owner: LifecycleOwner, key: String, observer: Observer<T>){
        LiveEventBus.get<T>(key).observeSticky(owner, observer)
    }















}